package fl.ass.service.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import cmm.service.core.framework.biz.BaseBizImpl;
import cmm.service.core.framework.dao.IBaseDao;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import fl.ass.facade.condition.AssDealSellCostQC;
import fl.ass.facade.dto.AssDealSellCostDTO;
import fl.ass.service.dao.AssDealSellCostMapper;
import fl.ass.service.po.AssDealSellCost;
import fl.ass.service.service.IAssDealSellCostService;
import fl.ass.service.transform.AssDealSellCostTransform;


/**
 * @Description: 处置-变卖费用信息表 服务层接口实现
 * @Description: 类中已经实现了简单增删改查操作,可以直接使用,如果有需要重写该方法即可：
 * @Description: 1、add(TVO entity) 2、removeById(Long id) 3、modify(DTO entity) 4、selectById(Long id)	5、searchListPage(Pager page) 7、searchList(DTO dto)   
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class AssDealSellCostServiceImpl extends BaseBizImpl<AssDealSellCost, AssDealSellCostDTO, AssDealSellCostQC> implements IAssDealSellCostService {
	
	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(IAssDealSellCostService.class);
	
	@Autowired
	private AssDealSellCostMapper assDealSellCostMapper;
	
	@Override
	public List<AssDealSellCostDTO> searchList(AssDealSellCostQC condition) throws BaseException {
		if(null == condition) return new ArrayList<AssDealSellCostDTO>();
		List<AssDealSellCost> list = this.assDealSellCostMapper.selectList(condition);
		return AssDealSellCostTransform.toDTOList(list);
	}
	
	@Override
	public IBaseDao<AssDealSellCost,AssDealSellCostQC> getDao() {
		return this.assDealSellCostMapper;
	}

	@Override
	public boolean batchAddAssDealSellCost(List<AssDealSellCostDTO> dtoList)
			throws BaseException {
		try {
			if(CollectionUtils.isNotEmpty(dtoList)){
				for (AssDealSellCostDTO assDealSellCostDTO : dtoList) {
					if(StringUtils.isNotEmpty(assDealSellCostDTO.getId())){
						boolean modify = this.modify(assDealSellCostDTO);
						if(!modify){
						    BaseLogUtils.newLogger("修改拖车明细费用信息失败").setKeys("assDealSellCostDTO:" + JSON.toJSONString(assDealSellCostDTO)).info();
							return false;
						}
					}else{
						Long add = this.add(assDealSellCostDTO);
						if(add<0){
						    BaseLogUtils.newLogger("新增拖车明细费用信息失败").setKeys("assDealSellCostDTO:" + JSON.toJSONString(assDealSellCostDTO)).info();
							return false;
						}
					}
				}
			}
		} catch (Exception e) {
		    BaseLogUtils.newLogger("保存杂费信息异常").setThrowable(e).info();
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_603, "保存杂费信息异常.");
		}
		return true;
	}
}

